<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>开发平台</title>
<script src="${ctx}/common/plateform/base/jquery/jquery.min.js"></script>
<script src="${ctx}/common/plateform/base/bootstrap/bootstrap.min.js"></script>
<link href="${ctx}/common/plateform/base/bootstrap/bootstrap.min.css" rel="stylesheet">
<link href="${ctx}/common/plateform/plugins/adminlte/AdminLTE.css" rel="stylesheet">
<script src="${ctx}/common/plateform/base/layer/layer.js"></script>
<link href="${ctx}/common/plateform/base/fonts/font-awesome.min.css" rel="stylesheet">
<link href="${ctx}/common/plateform/base/utils/plateform.css" rel="stylesheet" />
<link href="${ctx}/common/plateform/base/utils/mystyle.css" rel="stylesheet" />
<script src="${ctx}/common/plateform/base/utils/jquery-md5-min.js"></script>
<!--[if lt IE 10]>
<script src="${ctx}/common/plateform/plugins/ie/html5shiv.min.js"></script>
<script src="${ctx}/common/plateform/plugins/ie/respond.min.js"></script>
<![endif]-->
<script>

var ctx = '${ctx}';
</script>
<script type="text/javascript">
	function viewVerifyCode() {
		var r = "";
		if (undefined != ctx)
			r = ctx;
		document.getElementById("verifyCode").style.visibility = "visible";
		document.getElementById("verifyCode").src = ctx + "/web/CheckRandCode?" + Math.random();
	}
</script>
</head>
<style>
.login_wrap {
	background: url("${ctx}/images/plateform/login_bg_plateform.jpg") no-repeat;
	background-size: 100%;
	margin-top: 10px;
}
</style>

<body>
<div class="container">
		<h1 class="login_title ">
			<p class="pull-left"><p>快速开发平台</p> <span>欢迎登录！</span></p>
			<p class="pull-right login_tools">
				<span> <a href="${ctx}/sendPage/plateform/web/reg/user-reg">立即注册</a> </span>
				<span> <a href="${ctx}/sendPage/plateform/web/reg/set-passwd">忘记密码</a> </span>
			</p>
		</h1>
	</div>
	<div class="login_wrap">
		<div class="container">
			<div class="row">
				<div class="col-md-8"></div>
				<div class="col-md-4">

					<!-- login start -->
					<div class="login-box">
					<c:if test="${empty loginUser}">
						<h6>用户登录</h6>
						<form action="javascript:;" method="post" id="inputForm" name="inputForm" class="inputForm">
							<input id="password_form" name="password" type="hidden" />
							<input id="randCode_form" name="rand" type="hidden" />
							<input id="username_form" name="username" type="hidden" />
							<div class="form-group has-feedback">
								<input id="userEname" class="form-control" tabindex="1"
									placeholder="输入登录用户名" type="text" value="" maxlength="30"/> <span
									class="fa fa-user form-control-feedback"></span>
							</div>
							<div class="form-group has-feedback">
								<input type="password" id="upass" tabindex="2" class="form-control fft"
									placeholder="输入登录密码" value="" maxlength="30"> <span
									class="fa fa-lock form-control-feedback"></span>
							</div>

							<div class="form-group has-feedback">
								<input id="rand" size="4" tabindex="3" style="width:50%; margin-right:5px;"
									class="form-control" placeholder="输入验证码" maxlength="6"> <input name="flagDiv"
									id="flagDiv" type="hidden" value="" /> <img border="0"
									id="verifyCode" src="" onclick="viewVerifyCode();" align="absmiddle" />
								<script>
									viewVerifyCode();
								</script>
								<span class="fa fa-pencil form-control-feedback"></span>
							</div>
						</form>
						<div class="tools">
							<div id="error-message" class="col-sm-12 msg"></div>
						</div>
						<div class="login_btn">
							<div class="text-center">
								<button id="btn-login" type="button" class="btn btn-block btn-primary f16" onclick="sumbit()">登 录</button>
							</div>
							<div style="color:#0044cc; text-align: center">体验用户：<span>test</span><span style="margin-left:10px;">密码：test123456</span> </div>
						</div>
						<!-- /.login-box-body -->
						<!-- login end -->
					</c:if>
					<c:if test="${!empty loginUser}">
						<h6 style="font-weight:normal;">已登录用户</h6>
						<div class="form-group">
							<div class="col-lg-12 col-xs-12 p5">
								<div class="col-lg-offset-3 col-xs-offset-3 col-lg-6 col-xs-6">
									<img src="${ctx}/images/plateform/person2.png" class="img-responsive img-circle">
								</div>
								<div class="col-lg-12 col-xs-12"><h5 class="text-center">${loginUser.userCname}</h5></div>
							</div>
						</div>
						<div class="form-group">
							<div class="col-lg-offset-3 col-xs-offset-3 col-lg-3 col-xs-3 pt15">
								<h5 class="text-center"><a href="${ctx}/sendPage/plateform/admin/index-home-sys">登 录</a></h5>
							</div>
							<div class="col-lg-3 col-xs-3 pt15">
								<h5 class="text-center"><a href="${ctx}/logout?go=${ctx}/">退 出</a></h5>
							</div>
						</div>
					</c:if>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- foot start -->
	<center>
  		<footer class="login-footer text-center" style="margin-top:10px; margin-bottom:10px;">
			<p class="col-sm-12 ">Copyright &copy;  www.iussoft.com 版权所有 快速开发平台小组</p>
		</footer>
    </center>
	<!-- foot start -->

</body>

<script type="text/javascript">
		//解决ie不支持trim
		$(document).ready(
	           function(){
	           		 $("#userEname").focus();
	                 if(!String.prototype.trim) {
	                     String.prototype.trim = function () {
	                          return this.replace(/^\s+|\s+$/g,'');
	                     };
	               }
	           }
	      );
	    //回车登录
		document.onkeydown=function mykeyDown(e){
		      //compatible IE and firefox because there is not event in firefox
			   e = e || window.event;//兼容IE8
		       if(e.keyCode == 13) {sumbit();}
		       return;
		};
		//登录操作
		function sumbit(){
			var uname = $('#userEname').val();
			var upass = $('#upass').val();
			if(uname==null|| uname==""){
				setErrMsg('请输入用户名');
				$('#userEname').focus();
				return;
			}
			if(upass==null|| upass==""){
				setErrMsg('请输入密码');
				$('#upass').focus();
				return;
			}
            var rand = $("#rand").val();
            if(rand==null|| rand==""){
                setErrMsg('请输入验证码');
                $('#rand').focus();
                return;
            }
			var index_load = layer.load(1, {shade: false});
			$("#password_form").val(upass.md5());
			$("#randCode_form").val(rand);
			$("#username_form").val(uname);
			var formUrl =ctx+"/res/uct/login";
			//数据提交
			$.ajax({
				url:formUrl,
				type:'post',
				data: $("#inputForm").serialize(),
				success:function(data){
					var jdata = jQuery.parseJSON(data);
					//console.log(jdata);
					if (jdata.flag == 'T') {
						//window.location.href="${ctx}/sendPage/plateform/admin/index";
						var jsonObj = jQuery.parseJSON(jdata.msg);
						if("manager"!=jsonObj.userType){
                            layer.alert("您暂时无权限访问开发平台！");
                            layer.load(1, {shade: false});
                            window.location.href = "${ctx}/logout?go=${ctx}/"
						}else{
                            if(jsonObj.customerType!=null&&jsonObj.customerType!=''&&jsonObj.customerType!=undefined){
                                if('91'==jsonObj.auditStatus){
                                    window.location.href="${ctx}/sendPage/plateform/admin/index-home-sys";
								}else{
                                    window.location.href="${ctx}/sendPage/plateform/admin/index-user-entry-audit";
								}
                            }else{
                                window.location.href="${ctx}/sendPage/plateform/admin/index-user-entry";
							}
						}
					} else {
						setErrMsg(jdata.msg);
                        viewVerifyCode();
						clearForm();
					}
					layer.close(index_load);
				},error:function(data){
					layer.close(index_load);
					setErrMsg('与服务器连接失败');
                    viewVerifyCode();
				}
			});
		}

		//清空表单数据
		function clearForm(){
			$("#upass").val("");
			$("#userEname").val("");
            $("#rand").val("");
		}

		function setErrMsg(msg){
			$("#error-message").html("<font color='red'>"+msg+"</font>");
		}
	</script>
</html>
